package com.imagecollector.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imagecollector.domain.dto.RewardRecordSaveDTO;
import com.imagecollector.domain.dto.RewardRecordSearchDTO;
import com.imagecollector.domain.entity.TaskRewardRecord;
import com.imagecollector.mapper.TaskRewardRecordMapper;
import com.imagecollector.service.ITaskRewardRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 任务打款记录表 服务实现类
 * </p>
 *
 * @author wrf
 * @since 2024-07-31
 */
@Service
public class TaskRewardRecordServiceImpl extends ServiceImpl<TaskRewardRecordMapper, TaskRewardRecord> implements ITaskRewardRecordService {

    @Override
    public List<TaskRewardRecord> getByUserId(Long currentId) {
        return lambdaQuery().eq(TaskRewardRecord::getUserId, currentId).list();
    }

    @Override
    public boolean createRewardRecord(RewardRecordSaveDTO rewardRecordSaveDTO) {
        TaskRewardRecord taskRewardRecord = new TaskRewardRecord()
                .setAuditRecordId(rewardRecordSaveDTO.getAuditRecordId())
                .setPictureUrl(rewardRecordSaveDTO.getPictureUrl())
                .setReward(rewardRecordSaveDTO.getReward())
                .setRewardUserId(rewardRecordSaveDTO.getRewardUserId())
                .setTaskId(rewardRecordSaveDTO.getTaskId())
                .setUserId(rewardRecordSaveDTO.getUserId());
        save(taskRewardRecord);
        return true;
    }

    @Override
    public Page<TaskRewardRecord> getPaymentList(RewardRecordSearchDTO rewardRecordSearchDTO) {
        LambdaQueryWrapper<TaskRewardRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(rewardRecordSearchDTO.getId() != null, TaskRewardRecord::getId, rewardRecordSearchDTO.getId())
                .eq(rewardRecordSearchDTO.getRewardUserId() != null, TaskRewardRecord::getRewardUserId, rewardRecordSearchDTO.getRewardUserId())
                .eq(rewardRecordSearchDTO.getUserId() != null, TaskRewardRecord::getUserId, rewardRecordSearchDTO.getUserId())
                .eq(rewardRecordSearchDTO.getTaskId() != null, TaskRewardRecord::getTaskId, rewardRecordSearchDTO.getTaskId())
                .between(rewardRecordSearchDTO.getCreateTimeBegin() != null && rewardRecordSearchDTO.getCreateTimeEnd() != null,
                        TaskRewardRecord::getCreateTime, rewardRecordSearchDTO.getCreateTimeBegin(), rewardRecordSearchDTO.getCreateTimeEnd())
                .between(rewardRecordSearchDTO.getRewardBegin() != null && rewardRecordSearchDTO.getRewardEnd() != null,
                        TaskRewardRecord::getReward, rewardRecordSearchDTO.getRewardBegin(), rewardRecordSearchDTO.getRewardEnd());
        return page(new Page<>(rewardRecordSearchDTO.getPageNo(), rewardRecordSearchDTO.getPageSize()), queryWrapper);
    }
}
